package com.yhgarden.bbs.service.impl.thirdPartApi;

import com.yhgarden.bbs.model.enums.StatusCode;
import com.yhgarden.bbs.model.response.BaseResponse;
import com.yhgarden.bbs.service.api.thirdPartApi.AliyunAreasService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class AliyunAreasServiceImpl implements AliyunAreasService {

    @Autowired
    private RestTemplate restTemplate;

    @Override
    public BaseResponse getProvinces() {
        BaseResponse response = new BaseResponse(StatusCode.SUCCESS);
        Object provincesJson = restTemplate.getForObject("http://datavmap-public.oss-cn-hangzhou.aliyuncs.com/areas/csv/100000_province.json",Object.class);
        response.setData(provincesJson);
        return response;
    }

    @Override
    public BaseResponse getCities(String adcode) {
        BaseResponse response = new BaseResponse(StatusCode.SUCCESS);
        Object citiesJson = restTemplate.getForObject("http://datavmap-public.oss-cn-hangzhou.aliyuncs.com/areas/csv/"+adcode+"_city.json",Object.class);
        response.setData(citiesJson);
        return response;
    }

    @Override
    public BaseResponse getDistricts(String adcode) {
        BaseResponse response = new BaseResponse(StatusCode.SUCCESS);
        Object districtsJson = restTemplate.getForObject("http://datavmap-public.oss-cn-hangzhou.aliyuncs.com/areas/csv/"+adcode+"_district.json",Object.class);
        response.setData(districtsJson);
        return response;
    }
}
